package abaco.gui.textfield.listener;

import java.awt.Component;
import java.awt.event.KeyEvent;

import javax.swing.JPanel;

import abaco.gui.Manager;
import abaco.gui.Panel;
import abaco.gui.textfield.TextField;

public class KeyListener implements java.awt.event.KeyListener {
	protected TextField textField;

	public KeyListener(TextField textField) {
		this.textField = textField;
	}

	@Override
	public void keyPressed(KeyEvent evt) {
		if (evt.getKeyCode() == KeyEvent.VK_V && evt.isControlDown()) {
			System.out.println(" clicked ctrl +  v");
			//TODO implements
		}

		if (evt.getKeyCode() == KeyEvent.VK_X && evt.isControlDown()) {
			System.out.println(" clicked ctrl +  x");
			//TODO implements
		}

		if (evt.getKeyCode() == java.awt.event.KeyEvent.VK_C && evt.isControlDown()) {
			System.out.println(" clicked ctrl +  c");
			//TODO implements
		}
		
		if (evt.getKeyCode() == KeyEvent.VK_DELETE) {
			System.out.println(" clicked DELETE	");
			Manager manager  = Manager.getInstance();
			Component focused = manager.getCurrentFocused();
			JPanel  parent = (JPanel) focused.getParent();
			//TODO tranferis para o código feito Drawer.remove() ou relace
			if(focused instanceof TextField) {
				
				parent.setBackground(MouseListener.SELECT);
				manager.setCurrentFocused(parent);
				
			} else if(focused instanceof JPanel) {
				parent.remove(focused);
				parent.revalidate();
			}
			//TODO verificar se está no estado de selecionado e então deletar toda a pilha de objetos associados
			
		}
		
		if (evt.getKeyCode() == KeyEvent.VK_ESCAPE) {
			System.out.println(" clicked ESC");
			//TODO mover esses atributos estaticos(ex.:SELECT,DESELECT, etc) para uma classe abstrata ou interface
			if(this.textField.getBackground() == MouseListener.SELECT) {
				this.textField.setBackground(MouseListener.DESELECT);
			}
		}
	}
	@Override
	public void keyReleased(KeyEvent e) {
		// TODO Auto-generated method stub
	}
	@Override
	public void keyTyped(KeyEvent e) {
		// TODO Auto-generated method stub
	}

}
